package bio.chatproject.client;

import bio.chatproject.util.Constants;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author charwayH
 */
public class ClientChat {
    private static Scanner scanner;
    public static void main(String[] args) {
        login();
    }

    /**
     * 登录
     */
    private static void login() {
        scanner = new Scanner(System.in);
        System.out.print("请输入用户名:");
        String name = scanner.next();
        System.out.print("请输入IP");
        String IP = scanner.next();
        try {
            Socket socket = new Socket(IP,Constants.PORT);
            // 为客户端的socket分配一个线程，专门负责收信息
            new ClientReader(socket,1,name).start();

            // 带上用户信息
            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
            // 登录消息
            dos.writeInt(1);
            dos.writeUTF(name.trim());
            dos.flush();

            chat();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    private static void chat(){

    }
}

